********************************************************************************
********************************************************************************
*       Date:       September 2016                                       
*
*       Purpose:   	Do-file to replicate the results of the article 
*                  	"Taxing higher incomes: What makes the high-income earners 
*					consent to more progressive taxation in Latin America?"  
*    
*					Data management do-file to code the variables     
*
*       Authors:    Sarah Berens (University of Cologne)     
*					Armin von Schiller (German Development Institute & Hertie School of Governance)       
********************************************************************************


* Merge data sets of LAPOP 2012 each country survey using the "append" function
* Source: http://datasets.americasbarometer.org/database-login/usersearch.php?year=2012
* save appended dataset as "LAPOP2012"

use LAPOP2012, clear
set more off 

* country ID
gen countryID=.
replace countryID=pais

label define country 17 "ARG" 10 "BOL" 15 "BRA" 13 "CHL" 8 "COL" 6 "CRI" 9 "ECU" ///
3 "ELS" 2 "GTM" 4 "HND" 1 "MEX" 21 "NIC" 7 "PAN" 12 "PAR" 11 "PER" 21 "RDO" ///
14 "URY" 16 "VEN" 22"HIT" 23 "JAM" 24 "GUY" 25"TTO" 26 "BLZ" 27"SUR"
label values countryID country

*****************
* DV: soc1
*****************
bysort pais: sum(soc1)
* Item is only asked in Argentina, Chile, Columbia, Costa Rica, Guatemala, Mexico, Venezuela, Peru, Uruguay, Brazil

gen prog_tax=.
replace prog_tax=soc1
replace prog_tax=3 if soc1==1
replace prog_tax=2 if soc1==2
replace prog_tax=1 if soc1==3
replace prog_tax=. if soc1==4
label var prog_tax "progressive taxation preference"
label define prog_tax 1"30-30" 2"40-30" 3"50-20" , modify
label values prog_tax prog_tax

gen tax_dummy=.
replace tax_dummy=0 if soc1==3
replace tax_dummy=0 if soc1==2
replace tax_dummy=1 if soc1==1
replace tax_dummy=. if soc1==4
label var tax_dummy "progressive taxation preference"
label define tax_dummy 1"50-20" 0 "30-30 or 40-30", modify
label values tax_dummy tax_dummy

gen tax_dummy_without_moderate=.
replace tax_dummy_without_moderate=0 if soc1==3
replace tax_dummy_without_moderate=. if soc1==2
replace tax_dummy_without_moderate=1 if soc1==1
replace tax_dummy_without_moderate=. if soc1==4
label var tax_dummy "progressive taxation preference"
label define tax_dummy_without_moderate 1"50-20" 0 "30-30", modify
label values tax_dummy_without_moderate tax_dummy_without_moderate

********************
* Independent Variable: Wealth
********************

* assets
gen tv=.
replace tv=1 if r1==1
replace tv=0 if r1==0

gen fridge=.
replace fridge=1 if r3==1
replace fridge=0 if r3==0

gen telephone=.
replace telephone=1 if r4==1
replace telephone=0 if r4==0

gen cell=.
replace cell=1 if r4a==1
replace cell=0 if r4a==0

gen car=.
replace car=1 if r5==1
replace car=0 if r5==2
replace car=0 if r5==3
replace car=0 if r5==0

gen multi_car=.
replace multi_car= 1 if r5==2
replace multi_car= 1 if r5==3
replace multi_car= 0 if r5==0
replace multi_car= 0 if r5==1

gen washing_machine=.
replace washing_machine=1 if r6==1
replace washing_machine=0 if r6==0

gen microwave=.
replace microwave=1 if r7==1
replace microwave=0 if r7==0

gen motorcycle=.
replace motorcycle=1 if r8==1
replace motorcycle=0 if r8==0

gen indoor_pl=.
replace indoor_pl=1 if r12==1
replace indoor_pl=0 if r12==0

gen indoor_bath=.
replace indoor_bath=1 if r14==1
replace indoor_bath=0 if r14==0

gen pc=.
replace pc=1 if r15==1
replace pc=0 if r15==0

gen internet=.
replace internet=1 if r18==1
replace internet=0 if r18==0

gen flatTV=.
replace flatTV=1 if r16==1
replace flatTV=0 if r16==0

gen sewage=.
replace sewage=1 if r26==1
replace sewage=0 if r26==0

set more off
mca tv fridge telephone cell car multi_car washing_machine microwave motorcycle indoor_pl indoor_bath pc internet flatTV sewage
mcaplot, overlay origin
predict wealth
sum wealth, de

* Turn it around: create wealth1: so that higher values reflect higher wealth
gen wealth1=6.14-wealth 
sum wealth1, de

alpha  tv fridge telephone cell car multi_car washing_machine microwave motorcycle indoor_pl indoor_bath pc internet flatTV sewage



******************
* Alternative measures: self-reported income, class identification etc.
******************

* household income
gen income=.
replace income=q10new
label var income "income"


gen income1=.
replace income1=q10new
replace income1=1 if q10new<=5
replace income1=2 if q10new>=6
replace income1=3 if q10new>9 & q10new!=.
replace income1=. if q10new>16
replace income1=. if q10new==.
label define income1 1 "low income" 2 "middle income" 3 "high income"
label values income1 income1


* class identity
gen class_id=.
replace class_id= 1 if mov1==5
replace class_id= 2 if mov1==4
replace class_id= 3 if mov1==3
replace class_id= 4 if mov1==2
replace class_id= 5 if mov1==1
label define class_id 5"upper class" 4"upper middle class" 3"middle class" 2"lower middle class" 1"lower class", modify
label values class_id class_id
label var class_id "Class identity"

********************
* Independent Variable: trust in institutions and respect in institutions
********************

* to what  extent to you think that courts in your country guarantee a fair trial?
gen fair_trial=.
replace fair_trial=1 if b1==1
replace fair_trial=2 if b1==2
replace fair_trial=3 if b1==3
replace fair_trial=4 if b1==4
replace fair_trial=5 if b1==5
replace fair_trial=6 if b1==6
replace fair_trial=7 if b1==7
label define fair_trial 1"not at all" 7"a lot"
label values fair_trial fair_trial
label var fair_trial "fair courts"

*trust in national legislature
gen trust_legis=.
replace trust_legis=1 if b13==1
replace trust_legis=2 if b13==2
replace trust_legis=3 if b13==3
replace trust_legis=4 if b13==4
replace trust_legis=5 if b13==5
replace trust_legis=6 if b13==6
replace trust_legis=7 if b13==7
label define trust_legis 1"not at all" 7"a lot"
label values trust_legis trust_legis
label var trust_legis "trust in national legislature"

* Independent variable 1: respect for pol. institutions
* respect for political institutions
gen respect_polinst=.
replace respect_polinst= 1 if b2==1
replace respect_polinst= 2 if b2==2
replace respect_polinst= 3 if b2==3
replace respect_polinst= 4 if b2==4
replace respect_polinst= 5 if b2==5
replace respect_polinst= 6 if b2==6
replace respect_polinst= 7 if b2==7
labe values respect_polinst trust_legis
label var respect_polinst "respect in political institutions"


* trust in justice system
gen trust_justice=.
replace trust_justice= 1 if b10a== 1
replace trust_justice= 2 if b10a== 2
replace trust_justice= 3 if b10a== 3
replace trust_justice= 4 if b10a== 4
replace trust_justice= 5 if b10a== 5
replace trust_justice= 6 if b10a== 6
replace trust_justice= 7 if b10a== 7
label values trust_justice trust_legis
label var trust_justice "trust in justice syst."

* trust in parties
gen trust_parties=.
replace trust_parties= 1 if b21== 1
replace trust_parties= 2 if b21== 2
replace trust_parties= 3 if b21== 3
replace trust_parties= 4 if b21== 4
replace trust_parties= 5 if b21== 5
replace trust_parties= 6 if b21== 6
replace trust_parties= 7 if b21== 7
label values trust_parties trust_legis
label var trust_parties "trust in political parties"

* trust in local or municipla government
gen trust_localgovt=.
replace trust_localgovt= 1 if b32== 1
replace trust_localgovt= 2 if b32== 2
replace trust_localgovt= 3 if b32== 3
replace trust_localgovt= 4 if b32== 4
replace trust_localgovt= 5 if b32== 5
replace trust_localgovt= 6 if b32== 6
replace trust_localgovt= 7 if b32== 7
label values trust_localgovt trust_legis
label var trust_localgovt "trust in local/municipal government"

***************
* Institutional Trust
***************
* Independent variable 2: trust in institutions

pca b1 respect_polinst b3 trust_justice trust_legis b18 trust_parties b31 
predict reliability_avs

*****************
* Control variables
*****************

* female; based on Q1
gen gender=.
replace gender= 0 if q1==1
replace gender= 1 if q1==2
label define gender 0"male" 1"female"
label values gender gender

* education (starting with 0= no education, to +18 years of education)
gen edu_years=.
replace edu_years=ed
label var edu_years "years of edu."

*age; based on q2
gen age=.
replace age=q2
label var age "age"

* age squared
gen age_squared=.
replace age_squared=age*age

* marital status
gen married=.
replace married= 1 if q11==2
replace married= 1 if q11==3
replace married= 0 if q11==1
replace married= 0 if q11==4
replace married= 0 if q11==5
replace married= 0 if q11==6
label var married "married"
label define married 1"married" 0"not married"
label values married married

* household size
gen household_size=.
replace household_size= q12c

* dependants 
gen dependants=.
replace dependants= q12b


* urban/rural
gen urban=.
replace urban=1  if tamano==1
replace urban=1  if tamano==2
replace urban=1  if tamano==3
replace urban=1  if tamano==4
replace urban=0  if tamano==5
label define urban 1 "urban" 0 "rural", modify
label values urban urban


* employment status
gen emp_stat2=.
replace emp_stat2= 1 if ocup1a==2
replace emp_stat2= 1 if ocup1a==3
replace emp_stat2= 1 if ocup1a==4
replace emp_stat2= 1 if ocup1a==5
replace emp_stat2= 2 if ocup1a==1
replace emp_stat2= 1 if ocup4a==2
replace emp_stat2= 3 if ocup4a==3
replace emp_stat2= 4 if ocup4a==4
replace emp_stat2= 4 if ocup4a==5
replace emp_stat2= 5 if ocup4a==6
replace emp_stat2= 4 if ocup4a==7
label variable emp_stat2 "employment status"
label define emp_stat2 1 "employed"  2"public employee" 3"unemployed" 4"non-employed" 5"retired", modify
label values emp_stat2 emp_stat2


* economic situation
gen eco_sit=.
replace eco_sit=idio1
replace eco_sit=1 if idio1==5
replace eco_sit=2 if idio1==4
replace eco_sit=3 if idio1==3
replace eco_sit=4 if idio1==2
replace eco_sit=5 if idio1==1
label define eco_sit 5"very good" 4"good" 3"neither/nor" 2"bad" 1"very bad", modify
label values eco_sit eco_sit 


* social trust: how trustworthy do you think that peopel around you are? (1= very trustworthy, 4= not at all trustworthy)
* recoded so that high values mean high trust
gen social_trust=.
replace social_trust= it1
replace social_trust= 1 if it1==4
replace social_trust= 2 if it1==3
replace social_trust= 3 if it1==2
replace social_trust= 4 if it1==1
label var social_trust "social trust"
label define social_trust 1"Untrustworthy" 2"Not very trustworthy" 3"Somewhat trustworthy" 4"Very trustworthy"
label values social_trust social_trust


* political ideology; l1; 10=left to 1= right
gen left=.
replace left=1 if l1==10
replace left=2 if l1==9
replace left=3 if l1==8
replace left=4 if l1==7
replace left=5 if l1==6
replace left=6 if l1==5
replace left=7 if l1==4
replace left=8 if l1==3
replace left=9 if l1==2
replace left=10 if l1==1
label var left "left ideology"

* redistributive preference; gov't should reduce income inequality (higher values= individual want more redistribution)
gen redistribution=.
replace redistribution= ros4
label var redistribution "pref. for redistribution"

* preference for state ownership of companies
gen stateowner=.
replace stateowner= ros1
label var stateowner "state should own most important companies"
* turn around: privatization pref
gen privatization=. 
replace privatization=8-ros1 


* social assistance beneficiaries are lazy: peopole who get help from the govt social assistance are lazy, do you agree?
gen lazy=.
replace lazy= 1 if cct3==1
replace lazy= 2 if cct3==2
replace lazy= 3 if cct3==3
replace lazy= 4 if cct3==4
replace lazy= 5 if cct3==5
replace lazy= 6 if cct3==6
replace lazy= 7 if cct3==7
label define agree 1"very much disagree" 7"very agree"
label values lazy agree
label var lazy "beneficiaries of public social assistance are lazy"

* economic mobility
gen mobility=.
replace mobility= 1 if q10e==3
replace mobility= 2 if q10e==2
replace mobility= 3 if q10e==1
label var mobility "economic mobility over past two years"
label define mobility 1"decreased" 2"remained the same" 3"increased"
label values mobility mobility



*********************
* Drop missings
*********************
drop if tax_dummy==.
drop if tax_dummy==.a
drop if tax_dummy==.b
*drop if wealth_group==.
drop if  gender==. 
drop if  gender==.a
drop if  gender==.b 
drop if age==. 
drop if age==.a
drop if age==.b
drop if edu_years==. 
drop if edu_years==.a
drop if edu_years==.b
drop if edu_years==.c 
drop if emp_stat2==.
drop if emp_stat2==.a
drop if emp_stat2==.b
drop if mobility==. 
drop if mobility==.a 
drop if mobility==.b
drop if household_size==. 
drop if household_size==.a 
drop if household_size==.b
drop if married==.   
drop if married==.a   
drop if married==.b 
drop if lazy==.
drop if lazy==.a
drop if lazy==.b
drop if privatization==.
drop if privatization==.a
drop if privatization==.b
drop if redistribution==.
drop if redistribution==.a
drop if redistribution==.b
drop if class_id==.
drop if class_id==.a
drop if class_id==.b
drop if respect_polinst==.
drop if respect_polinst==.a
drop if respect_polinst==.b
drop if trust_parties==.
drop if social_trust==.
drop if social_trust==.a
drop if social_trust==.b
drop if urban==.
drop if urban==.a
drop if urban==.b
drop if b1==.a
drop if b1==.b
drop if b1==.c


***
* By country: create wealth groups (3 groups)
*****
sort country
by country: sum wealth1,d

sum wealth1 if pais==1,d 
*

gen rich75_3pais=.
replace rich75_3pais=1 if wealth1>=  r(p75) & wealth1 !=.  & pais==1
replace rich75_3pais=0 if wealth1<   r(p75)  & wealth1 !=. & pais==1

gen mid25_75_3pais=.
replace mid25_75_3pais= 1 if wealth1>  r(p25)  & wealth1< r(p75) & wealth1 !=. & pais==1
replace mid25_75_3pais= 0 if wealth1> r(p75) & wealth1 !=. & pais==1
replace mid25_75_3pais= 0 if wealth1< r(p25)  & wealth1 !=. & pais==1

gen low25_3pais=.
replace low25_3pais= 1 if wealth1<=  r(p25)  & wealth1 !=.  & pais==1
replace low25_3pais= 0 if wealth1>  r(p25)  & wealth1 !=. & pais==1


*
sum wealth1 if pais==2,d 
*

replace rich75_3pais=1 if wealth1>=  r(p75) & wealth1 !=.  & pais==2
replace rich75_3pais=0 if wealth1<   r(p75)  & wealth1 !=. & pais==2

replace mid25_75_3pais= 1 if wealth1>  r(p25)  & wealth1< r(p75) & wealth1 !=. & pais==2
replace mid25_75_3pais= 0 if wealth1> r(p75) & wealth1 !=. & pais==2
replace mid25_75_3pais= 0 if wealth1< r(p25)  & wealth1 !=. & pais==2

replace low25_3pais= 1 if wealth1<=  r(p25)  & wealth1 !=.  & pais==2
replace low25_3pais= 0 if wealth1>  r(p25)  & wealth1 !=. & pais==2


*
sum wealth1 if pais==6,d 
*

replace rich75_3pais=1 if wealth1>=  r(p75) & wealth1 !=.  & pais==6
replace rich75_3pais=0 if wealth1<   r(p75)  & wealth1 !=. & pais==6

replace mid25_75_3pais= 1 if wealth1>  r(p25)  & wealth1< r(p75) & wealth1 !=. & pais==6
replace mid25_75_3pais= 0 if wealth1> r(p75) & wealth1 !=. & pais==6
replace mid25_75_3pais= 0 if wealth1< r(p25)  & wealth1 !=. & pais==6

replace low25_3pais= 1 if wealth1<=  r(p25)  & wealth1 !=.  & pais==6
replace low25_3pais= 0 if wealth1>  r(p25)  & wealth1 !=. & pais==6


sum wealth1 if pais==8,d 
*

replace rich75_3pais=1 if wealth1>=  r(p75) & wealth1 !=.  & pais==8
replace rich75_3pais=0 if wealth1<   r(p75)  & wealth1 !=. & pais==8

replace mid25_75_3pais= 1 if wealth1>  r(p25)  & wealth1< r(p75) & wealth1 !=. & pais==8
replace mid25_75_3pais= 0 if wealth1> r(p75) & wealth1 !=. & pais==8
replace mid25_75_3pais= 0 if wealth1< r(p25)  & wealth1 !=. & pais==8

replace low25_3pais= 1 if wealth1<=  r(p25)  & wealth1 !=. & pais==8
replace low25_3pais= 0 if wealth1>  r(p25)  & wealth1 !=. & pais==8


sum wealth1 if pais==11,d 
*

replace rich75_3pais=1 if wealth1>=  r(p75) & wealth1 !=.  & pais==11
replace rich75_3pais=0 if wealth1<   r(p75)  & wealth1 !=. & pais==11

replace mid25_75_3pais= 1 if wealth1>  r(p25)  & wealth1< r(p75) & wealth1 !=. & pais==11
replace mid25_75_3pais= 0 if wealth1> r(p75) & wealth1 !=. & pais==11
replace mid25_75_3pais= 0 if wealth1< r(p25)  & wealth1 !=. & pais==11

replace low25_3pais= 1 if wealth1<=  r(p25)  & wealth1 !=.  & pais==11
replace low25_3pais= 0 if wealth1>  r(p25)  & wealth1 !=. & pais==11


 forvalues i = 13(1)17 {
 sum wealth1 if pais==`i' ,d 
*

replace rich75_3pais=1 if wealth1>=  r(p75) & wealth1 !=.  & pais==`i'
replace rich75_3pais=0 if wealth1<   r(p75)  & wealth1 !=. & pais==`i'

replace mid25_75_3pais= 1 if wealth1>  r(p25)  & wealth1< r(p75) & wealth1 !=. & pais==`i'
replace mid25_75_3pais= 0 if wealth1> r(p75) & wealth1 !=. & pais==`i'
replace mid25_75_3pais= 0 if wealth1< r(p25)  & wealth1 !=. & pais==`i'

replace low25_3pais= 1 if wealth1<=  r(p25)  & wealth1 !=.  & pais==`i'
replace low25_3pais= 0 if wealth1>  r(p25)  & wealth1 !=. & pais==`i'

          }

sum wealth1,d

gen wealth_group_3pais=.

replace wealth_group_3pais=1 if low25_3pais==1
replace wealth_group_3pais=2 if mid25_75_3pais==1
replace wealth_group_3pais=3 if rich75_3pais==1


label var wealth_group_3pais "weatlh group2"
label define wealth_group_3pais 1  "10-25" 2 "25-75" 3 "75-100" 
label values wealth_group_3pais wealth_group_3pais 


***
* By country: create wealth groups 90%
*****
sort country
by country: sum wealth1,d

sum wealth1 if pais==1,d 
*

gen rich90_3pais=.
replace rich90_3pais=1 if wealth1>=  r(p90) & wealth1 !=.  & pais==1
replace rich90_3pais=0 if wealth1<   r(p90)  & wealth1 !=. & pais==1


*
sum wealth1 if pais==2,d 
*

replace rich90_3pais=1 if wealth1>=  r(p90) & wealth1 !=.  & pais==2
replace rich90_3pais=0 if wealth1<   r(p90)  & wealth1 !=. & pais==2

*
sum wealth1 if pais==6,d 
*

replace rich90_3pais=1 if wealth1>=  r(p90) & wealth1 !=.  & pais==6
replace rich90_3pais=0 if wealth1<   r(p90)  & wealth1 !=. & pais==6


sum wealth1 if pais==8,d 
*

replace rich90_3pais=1 if wealth1>=  r(p90) & wealth1 !=.  & pais==8
replace rich90_3pais=0 if wealth1<   r(p90)  & wealth1 !=. & pais==8


sum wealth1 if pais==11,d 
*

replace rich90_3pais=1 if wealth1>=  r(p90) & wealth1 !=.  & pais==11
replace rich90_3pais=0 if wealth1<   r(p90)  & wealth1 !=. & pais==11



 forvalues i = 13(1)17 {
 sum wealth1 if pais==`i' ,d 
*

replace rich90_3pais=1 if wealth1>=  r(p90) & wealth1 !=.  & pais==`i'
replace rich90_3pais=0 if wealth1<   r(p90)  & wealth1 !=. & pais==`i'

          }

sum wealth1,d


label var rich90_3pais "top10rich"
label define rich90_3pais 0  "0-90" 1 "90-100" 
label values rich90_3pais rich90_3pais 


save LAPOP2012_workingfile_replication
